from django import forms
from django.contrib import admin
from django.utils.html import format_html
from basic_info.models import Brands



# Register your models here.

class BrandAdmin(admin.ModelAdmin):
    list_display = ('name', 'create_at', 'update_at', 'edit_button', 'delete_button')
    list_per_page = 10
    list_display_links = ('edit_button',)
    list_filter = ('name',)
    ordering = ('-update_at',)
    save_on_top = True

    def delete_button(self, obj):
        return format_html(
            f'<a  class = "el-button stop-submit el-button--danger el-button--small el-icon-delete" '
            f'onclick="href=\'/admin/basic_info/brands/{obj.id}/delete/\'">删除</a>')

    delete_button.allow_tags = True
    delete_button.short_description = '删除'

    def edit_button(self, obj):
        return format_html(
            f'<a  class= "el-button el-button--primary el-button--small el-icon-edit" '
            f'onclick="href=\'/admin/basic_info/brands/{obj.id}/change/\'">编辑</a>')

    edit_button.allow_tags = True
    edit_button.short_description = '编辑'



admin.site.register(Brands, BrandAdmin)
